import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const Layout = () => import('@/components/Layout')
const Login = () => import('@/views/login/index') // 登录页
const Main = () => import('@/views/index') // 主页

// 文章管理
const articleForm = () => import('@/views/article/articleForm/index') //写点什么
const ArticleList = () => import('@/views/article/articleList/index') //写了什么

const Record = () => import('@/views/record/index') //记录管理
const Message = () => import('@/views/message/index') //留言管理
const Comment = () => import('@/views/comment/index') //评论管理
const Friend = () => import('@/views/friend/index') //友链管理
const Picture = () => import('@/views/picture/index') //图片管理
const Resources = () => import('@/views/resources/index') //资源管理

const Product = () => import('@/views/product/index') //商品管理

const User = () => import('@/views/system/user/index') // 用户管理
const Type = () => import('@/views/system/type/index') //分类管理
const Menu = () => import('@/views/system/menu/index') //菜单管理

const Demo = () => import('@/views/threejs/demo/index') //代码管理
const Example = () => import('@/views/threejs/Example/index') //Threejs管理

// 固定的路由表
export const fixedRouter = [
  {
    path: '',
    component: Login,
    hidden: true
  },
  {
    path: '',
    component: Layout, //整体页面的布局(包含左侧菜单跟主内容区域)
    children: [
      {
        path: 'main',
        component: Main,
        meta: {
          title: '首页', //菜单名称
          roles: ['user', 'admin'], //当前菜单哪些角色可以看到
          icon: 'el-icon-info' //菜单左侧的icon图标
        }
      }
    ]
  }
]

// 需要权限判断展示的路由
export const permissionRouter = [
  {
    path: '/article',
    component: Layout,
    name: 'Article',
    meta: {
      title: '文章管理',
      icon: 'el-icon-s-order',
      roles: ['admin', 'user'] //菜单权限设置
    },
    children: [
      {
        path: 'articleList',
        name: 'ArticleList',
        component: ArticleList,
        meta: {
          title: '文章列表',
          roles: ['admin', 'user'] //菜单权限设置
        }
      },
      {
        path: 'articleAdd',
        name: 'articleAdd',
        component: articleForm,
        meta: {
          title: '文章新增',
          roles: ['admin', 'user'] //菜单权限设置
        }
      },
      {
        path: 'articleEdit/:id',
        name: 'ArticleEdit',
        component: articleForm,
        hidden: true,
        meta: {
          title: '文章修改',
          roles: ['admin', 'user'] //菜单权限设置
        }
      }
    ]
  },
  {
    path: '/record',
    component: Layout,
    name: 'Record',
    redirect: '/recordList',
    children: [
      {
        path: 'recordList',
        name: 'recordList',
        component: Record,
        meta: {
          title: '记录管理',
          icon: 'el-icon-s-data',
          roles: ['admin', 'user'] //菜单权限设置
        }
      }
    ]
  },
  {
    path: '/message',
    component: Layout,
    name: 'Message',
    redirect: '/messageList',
    children: [
      {
        path: 'messageList',
        name: 'messageList',
        component: Message,
        meta: {
          title: '留言管理',
          icon: 'el-icon-edit-outline',
          roles: ['admin', 'user'] //菜单权限设置
        }
      }
    ]
  },
  {
    path: '/comment',
    component: Layout,
    name: 'Comment',
    redirect: '/commentList',
    children: [
      {
        path: 'commentList',
        name: 'commentList',
        component: Comment,
        meta: {
          title: '评论管理',
          icon: 'el-icon-s-comment',
          roles: ['admin', 'user'] //菜单权限设置
        }
      }
    ]
  },
  {
    path: '/friend',
    component: Layout,
    name: 'Friend',
    redirect: '/friendList',
    children: [
      {
        path: 'friendList',
        name: 'FriendList',
        component: Friend,
        meta: {
          title: '友链管理',
          icon: 'el-icon-share',
          roles: ['admin', 'user'] //菜单权限设置
        }
      }
    ]
  },
  {
    path: '/picture',
    component: Layout,
    name: 'Picture',
    redirect: '/pictureList',
    children: [
      {
        path: 'pictureList',
        name: 'PictureList',
        component: Picture,
        meta: {
          title: '图片管理',
          icon: 'el-icon-picture',
          roles: ['admin', 'user'] //菜单权限设置
        }
      }
    ]
  },
  {
    path: '/resources',
    component: Layout,
    name: 'Resources',
    redirect: '/resourcesList',
    children: [
      {
        path: 'resourcesList',
        name: 'resourcesList',
        component: Resources,
        meta: {
          title: '资源管理',
          icon: 'el-icon-s-management',
          roles: ['admin', 'user'] //菜单权限设置
        }
      }
    ]
  },
  {
    path: '/product',
    component: Layout,
    name: 'Product',
    redirect: '/productList',
    children: [
      {
        path: 'productList',
        name: 'ProductList',
        component: Product,
        meta: {
          title: '商品管理',
          icon: 'el-icon-s-goods',
          roles: ['admin', 'user'] //菜单权限设置
        }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    name: 'System',
    meta: {
      title: '系统设置',
      icon: 'el-icon-s-tools',
      roles: ['admin', 'user'] //菜单权限设置
    },
    children: [
      {
        path: 'user',
        name: 'User',
        component: User,
        meta: {
          title: '用户管理',
          roles: ['admin', 'user'] //菜单权限设置
        }
      },
      {
        path: 'type',
        name: 'Type',
        component: Type,
        meta: {
          title: '分类管理',
          roles: ['admin', 'user']
        }
      },
      {
        path: 'menu',
        name: 'Menu',
        component: Menu,
        meta: {
          title: '菜单管理',
          roles: ['admin', 'user'] //菜单权限设置
        }
      }
    ]
  },
  {
    path: '/threejs',
    component: Layout,
    name: 'Threejs',
    meta: {
      title: 'Threejs',
      icon: 'el-icon-s-tools',
      roles: ['admin', 'user'] //菜单权限设置
    },
    children: [
      {
        path: 'example',
        name: 'Example',
        component: Example,
        meta: {
          title: 'Example',
          roles: ['admin', 'user'] //菜单权限设置
        }
      },
      {
        path: 'demo',
        name: 'Demo',
        component: Demo,
        meta: {
          title: 'Demo',
          roles: ['admin', 'user'] //菜单权限设置
        }
      }
    ]
  }
]

export default new VueRouter({
  routes: fixedRouter
})
